package com.breakfast.fun.util;

import com.breakfast.fun.App;
import com.breakfast.fun.dao.DaoMaster;
import com.breakfast.fun.dao.ProductCart;
import com.breakfast.fun.dao.ProductCartDao;

import org.greenrobot.greendao.query.Query;
import org.greenrobot.greendao.query.QueryBuilder;

import java.util.List;

/**
 * 封装一些业务上的数据库操作
 * Created by yukai on 2016/10/28.
 */

public class DaoUtil {

    /**
     * 获取本地数据库商品列表
     *
     * @param categoryId 分类ID
     * @param productId  产品ID
     * @param chooseDate 送达日期
     * @return
     */
    public static List<ProductCart> getProductList(int categoryId, int productId, String chooseDate) {
        QueryBuilder qb = getProductCartDao().queryBuilder();
        ProductCart productCart = new ProductCart(null, categoryId, productId, chooseDate);
        Query query = qb.where(
                ProductCartDao.Properties.Date.eq(productCart.getDate()), ProductCartDao.Properties.ProductId.eq(productCart.getProductId()))
                .build();
        return query.list();
    }

    public static ProductCartDao getProductCartDao() {
        return DaoMaster.newDevSession(App.getAppContext(), "zaofan.db").getProductCartDao();
    }
}
